// pages/cate/add/index.js
import { tips, confirm, coludRequest } from '../../util/util.js' 
Page({

  /**
   * 页面的初始数据
   */
  data: {
      id:'',
      title:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {      
      this.setData({id:options.id});
      this.getCate(options.id);
  },
  
  getTitle: function (e) {
    var val = e.detail.value;
    this.setData({title: val});
  },

  //提交
  submitAdd:function(){
    if(this.data.title==""){
       tips('请输入分类');
       return false;
    }
    coludRequest('admin', { module: 'cate', action:'update', id: this.data.id, params: {title: this.data.title }}, function (res) {
        tips('分类修改成功')
        setTimeout(res => {
          wx.navigateTo({
            url: '/pages/cate/index',
          })
        }, 1200)
    })
  },

  getCate:function(id){
    var that = this;
    coludRequest('admin', {module:'cate', action: 'query', map: {_id:id} }, function (res) {     
       that.setData({ title: res.result.data[0].title });
    })
  },

})